#!/usr/bin/env xonsh

$RAISE_SUBPROC_ERROR = True

from os.path import dirname,abspath,join

DIR = dirname(dirname(abspath(join(__file__))))

# SVG 必须是正方形，不然生成MAC的图标会报错
#SVG = join(DIR,"file/svg/ico.svg")

from shutil import which
from sys import platform

if which("rsvg-convert") is None:
  if platform == "darwin":
    brew install librsvg
  else:
    sudo apt install -y librsvg2-bin

cd @(DIR)

filename="trayTemplate"

for color in ['color','black']:
  svg=f"file/svg/tray/{color}.svg"
  outdir = join(DIR, "../ci/pkg/tray", color)
  mkdir -p @(outdir)
  for i in range(1,4):
    size=16*i
    if i > 1:
      suffix=f"@{i}x"
    else:
      suffix=""
    rsvg-convert -h @(size) -w @(size) @(svg) > @(outdir)/@(filename)@(suffix).png

cp @(outdir)/*.png @(DIR)/file/png/
